﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Marmat.Foundation;
using Marmat.FrameWork;
using Marmat.Template.WinForm;

namespace 测试项目.TestDemo
{
    public partial class TestFirstDemoEditForm : Form, IDocumentEditForm<TestDemoEntity>, Marmat.Foundation.IEditFormEditorStyle
    {
        public TestFirstDemoEditForm()
        {
            InitializeComponent();
            this.editFormStatusControl1.BindingField.DataSource = this.testFirstDemoDataSource1;
            this.editFormStatusControl1.BindingField.DataMember = "Status";
        }


        public IDocumentEditFormController<TestDemoEntity, TestDemoEntity[]> Controller { get; set; }

        void IDocumentEditForm<TestDemoEntity, TestDemoEntity[]>.Load(TestDemoEntity data)
        {
            IPermission permission = SystemCommand.GetService<IPermission>();
            this.testFirstDemoDataSource1.DataSource = data;

            this.Controller.AllowEdit = !this.Controller.AllowEdit;
            this.editFormStatusControl1.Controller = this.Controller;
            this.editFormStatusControl1.ClearButtonRegulation();
            this.editFormStatusControl1.AddButtonRegulation("草稿", new ButtonItem("提交"));
            this.editFormStatusControl1.AddButtonRegulation("审批中", new ButtonItem("通过"), new ButtonItem("拒绝"));
            this.editFormStatusControl1.AddButtonRegulation("已审批", new ButtonItem("重置"));
            this.editFormStatusControl1.Builder();
        }

        public void Editor()
        {
            this.testFirstDemoDataSource1.AllowEdit = true;
        }

        public void Preview()
        {
            this.testFirstDemoDataSource1.AllowEdit = false;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            var tmp = this.Parent.Location;
            MessageBox.Show(tmp.ToString());
        }

        public bool Verify()
        {
            return true;
        }

        private void editFormStatusControl1_ItemClick(object sender, IButtonItem e)
        {
            SystemCommand.GetService<IAlert>().Show(e.Caption ?? e.Name, AlertTypeEeum.Error);
        }

        private void TestFirstDemoEditForm_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            this.testFirstDemoDataSource1.DataSource.Status = "审批中";
            this.editFormStatusControl1.Status = "审批中";
            this.editFormStatusControl1.Builder();
            this.Controller.LoadDataObject();
        }

        private void editFormStatusControl1_ItemClick(object sender, EditFormStatusControlItemClickArgs e)
        {
            switch (e.Item.Name)
            {
                case "通过":
                    this.testFirstDemoDataSource1.DataSource.Status = "已审批";
                    break;
                case "提交":
                    this.testFirstDemoDataSource1.DataSource.Status = "审批中";
                    break;
                case "拒绝":
                    this.testFirstDemoDataSource1.DataSource.Status = "草稿";
                    break;
                case "重置":
                    this.testFirstDemoDataSource1.DataSource.Status = "草稿";
                    break;
                default:
                    break;
            }
            this.editFormStatusControl1.Status = this.testFirstDemoDataSource1.DataSource.Status;
            this.editFormStatusControl1.Builder();
            e.Cancel = true;
        }
    }
}
